package com.bamboocloud.im.controller;

import com.bamboocloud.im.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Auther xuwen
 * @Date 2021/12/9 16:19
 * @Version 1.0
 */
@RestController
public class DeptConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    //通过Ribbon实现的话，我们这里url地址应该是个变量，应该通过服务名访问
    //private static final String REST_URL_PREFIX = "http://localhost:8001";
    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-DEPT";

    @RequestMapping("/consumer/dept/add")
    public boolean add(Dept dept){
        return restTemplate.postForObject(REST_URL_PREFIX +"/dept/add",dept,Boolean.class);
    }
     @RequestMapping("/consumer/dept/get/{id}")
     public Dept get(@PathVariable("id") Long id){
        return restTemplate.getForObject(REST_URL_PREFIX +"/dept/get/"+id,Dept.class);
}
    @RequestMapping("/consumer/dept/gets")
    public List<Dept> gets(){
        return restTemplate.getForObject(REST_URL_PREFIX +"/dept/gets",List.class);
    }

/*    @RequestMapping("consumer/dept/delect/{id}")
    public boolean delete(@PathVariable("id") Long id){
        return restTemplate.delete(REST_URL_PREFIX+"/dept/delect/"+id);
    }*/
/*    @RequestMapping("/consumer/dept/update")
    public Dept update(Dept dept){
        return restTemplate.put(REST_URL_PREFIX+"/dept/delect",dept,Dept.class);
    }*/


}
